package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;



import com.itheima.constant.MessageConst;
import com.itheima.entity.Result;
import com.itheima.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.JedisPool;


import java.util.ArrayList;
import java.util.List;

/**
 * @author 黑马程序员
 * @Company http://www.ithiema.com
 * @Version 1.0
 */
@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Reference
    SetmealService setmealService;
    @Autowired
    JedisPool jedisPool;



    @RequestMapping("/getSetmeal")
    public Result getSetmeal(){
        try {
            return new Result(true, MessageConst.GET_SETMEAL_LIST_SUCCESS, JSON.parse(setmealService.getSetmealFromRedis()));
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConst.GET_SETMEAL_LIST_FAIL);
        }
    }

    @RequestMapping("/findDetailsById")
    public Result findDetailsById(Integer id){
        try {
            return new Result(true,MessageConst.QUERY_SETMEAL_SUCCESS, JSON.parse(setmealService.findDetailsByIdFromRedis(id)));
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConst.QUERY_SETMEAL_FAIL);
        }
    }

    @RequestMapping("/findById")
    public Result findById(Integer id){
        try {
            return new Result(true,MessageConst.QUERY_SETMEAL_SUCCESS, JSON.parse(setmealService.findByIdFromRedis(id)));
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConst.QUERY_SETMEAL_FAIL);
        }
    }

}
